<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            background: skyblue;
            width: 300px;
            height: 300px;
        }
        
        div  div{
            background: pink;
            height: 50px;
            width:50px;
        }
    </style>
</head>
<body>
    <div>
        <div></div>
    </div>

    <script>
        var innerDiv = document.querySelector('div > div');
        var outerDiv = document.querySelector('div');

        innerDiv.onclick = function(){
            alert("您点击了内层");
        }

        outerDiv.onclick = function(){
            alert("您点击了外层");
        }
    </script>
</body>
</html>